#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

int main()
{
	char str1[10], str2[10];
	scanf("%s, %s", &str1, &str2);
	char strs[100000][10];
	int i = 0;
	while (scanf("%s", &strs[i]) != EOF)
	{
		i++;
	}
	int flag = 0; 
	int flag1 = 0; 
	int flag2 = 0;
	while (strs[i] != NULL)
	{
		if (strs[i] == str1)
		{
			flag1 = 1;
		}
		if (strs[i] == str2)
		{
			flag2 = 1;
		}
	}

	int a
	if (flag1 == 0 || flag2 == 0)
	{
		printf("-1");
	}
	else
	{

	}
	return 0;
}